package eclipse.lib.sound;
import eclipse.util.*;
/** 
 * AudioDevice represents a collective playback utility that the Client uses to play audio media.
 * This currently support midi, mp3, and wav.
 */
public class AudioDevice 
{	
	private enum CodecType {mp3, mid, wav};
	private SoundPlayer wavCodec;
	private MidiPlayer	midCodec;
	private MpegPlayer	mp3Codec;
	private CodecType 	codecType;	
	/** Creates the Audio Playback device. */
	public AudioDevice()
	{
		wavCodec 	= new SoundPlayer();
		midCodec 	= new MidiPlayer();
		mp3Codec	= new MpegPlayer();		
	}
	/**
	 * Loads an Audio file to the device.
	 * @param sFile String path of the File in the form of an ERL string.
	 */
	public void loadAudio(String sFile)
	{
		if(		sFile.endsWith("mp3"))
		{			
			codecType = CodecType.mp3;
			mp3Codec.loadMP3(new ERL(sFile));
			System.out.println("loading mp3");
		}
		else if(sFile.endsWith("mid"))
		{
			codecType = CodecType.mid;
			midCodec.loadMidi(new ERL(sFile));
		}
		else if(sFile.endsWith("wav"))
		{
			codecType = CodecType.wav;
			wavCodec.loadAudio(new ERL(sFile));
		}		
	}	
	/** Plays the audio one time */
	public void playAudio()
	{
		if(		codecType == CodecType.mp3)		
			mp3Codec.playMP3();		
		else if(codecType == CodecType.mid)
				midCodec.playMidi();
		else if(codecType == CodecType.wav)
				wavCodec.playAudio();
	}
	/** Loops the audio until told to stop. */
	public void loopAudio()
	{
		if(		codecType == CodecType.mp3)		
			mp3Codec.loopMP3();			
		else if(codecType == CodecType.mid)
				midCodec.loopMidi();
		else if(codecType == CodecType.wav)
				wavCodec.playAudio();
	}
	/** Stops the playback of audio */
	public void stopAudio()
	{
		if(		codecType == CodecType.mp3)
				mp3Codec.stopMP3();
		else if(codecType == CodecType.mid)
				midCodec.stopMidi();
		else if(codecType == CodecType.wav)
				wavCodec.stopAudio();
	}
}
